extends NodeState


@export var player: Player
@export var playerJump: PlayerJump


func _on_process(delta : float) -> void:
	process_punch_coillder()
	process_air_time(delta)
	process_movement()


func _on_physics_process(_delta : float) -> void:
	pass


func _on_next_transitions() -> void:
	pass


func _on_enter() -> void:
	process_animation()

	# 进入状态时打开监听，允许发生碰撞
	player.damageEmitter.monitoring = true


func _on_exit() -> void:
	# 退出状态时关闭监听，停止发生碰撞
	player.damageEmitter.monitoring = false


func process_animation():
	player.animationPlayer.play(Player.ANIMATION_JUMPKICK)


# 跳跃攻击过程中不允许切换方向，只能沿之前的方向继续运动
func process_movement():
	player.move_and_slide()


func process_punch_coillder():
	var orientation = player.character_orientation()
	if orientation == 1:
		player.damageEmitter.scale.x = 1
	elif orientation == -1:
		player.damageEmitter.scale.x = -1


# 跳跃攻击过程中需要继续使用跳跃状态中的高度和高度速度进行位置的计算
func process_air_time(delta: float):
	player.characterSprite.position = Vector2.UP * playerJump.height

	playerJump.height += playerJump.height_speed * delta
	if playerJump.height < 0.0:
		playerJump.height = 0.0
		transition_state(Player.STATE_LAND)
	else:
		playerJump.height_speed -= player.gravity * delta
